#pragma once
#include <vector>

const CString FMCONST_PBATCH_DEFAULT_DATA_SEPARATOR_TAG                     = _T(",");
const CString FMCONST_PBATCH_DEFAULT_DATA_DELIMITER_TAG                     = _T("\"");
const CString FMCONST_PBATCH_DEFAULT_LOG_FILE_NAME_TAG                      = _T("splitlog.log");
const CString FMCONST_PBATCH_DEFAULT_TRACE_FILE_NAME_TAG                    = _T("SplitTrace.log");
const CString FMCONST_PBATCH_DEFAULT_LOG_FILE_NAME_EXTENSION_TAG            = _T(".log");
const CString FMCONST_PBATCH_DEFAULT_TEXT_FILE_NAME_EXTENSION_TAG           = _T(".txt");


class CTextDataSplit
{
public:
    CTextDataSplit(void);
    ~CTextDataSplit(void);

// Implementation
public:
    int SplitTextFileFirstLine(const CString& strTextFileName, const CString& strSeparator = FMCONST_PBATCH_DEFAULT_DATA_SEPARATOR_TAG, 
        const CString& strDelimiter = FMCONST_PBATCH_DEFAULT_DATA_DELIMITER_TAG, CStringList* pOutList = nullptr, int num  = 0 );
    int SplitTextFileMaxFieldLine(const CString& strTextFileName, const CString& strSeparator = FMCONST_PBATCH_DEFAULT_DATA_SEPARATOR_TAG, 
        const CString& strDelimiter = FMCONST_PBATCH_DEFAULT_DATA_DELIMITER_TAG, CStringList* pOutList = nullptr, int num  = 0 );



private:
// Attributes
    CStdioFile  m_stdfTraceFile;
    CStdioFile  m_stdfLogFile;

    CString     m_strLogFileName;

    BOOL        m_bCanWriteLog;
    BOOL        m_bAllowWriteLog;    
    
/// operations 
    CString GetFirstDataLine( const CString& strFileName );
    int SplitString( const CString& strTextData, const CString& strSeparator, std::vector<CString>& rVctStringList
        , const CString& strDelimiter = FMCONST_PBATCH_DEFAULT_DATA_DELIMITER_TAG);
    int SplitString( const CString& strTextData, std::vector<CString>& rVctStringList
        , const CString& strSeparator = FMCONST_PBATCH_DEFAULT_DATA_SEPARATOR_TAG);

    void Tokenize(CString s, CString delimits, CStringList* pList, BOOL trim = FALSE, CString nullSubst = _T(""));
    void Split(const CString& src, CString delimit, CStringList* pOutList, int num = 0, CString nullSubst =  _T(""));

    BOOL GetCanWriteLog();
    void SetCanWriteLog(BOOL val) { m_bCanWriteLog = val; }

    CStdioFile& GetTraceFile() { return m_stdfTraceFile; }
    //void StdfLogFile(CStdioFile val) { m_stdfTraceFile = val; }

    BOOL GetAllowWriteLog() const { return m_bAllowWriteLog; }
    void SetAllowWriteLog(BOOL val) { m_bAllowWriteLog = val; }

    CString GetLogFileName() const { return m_strLogFileName; }
    void SetLogFileName(CString val) { m_strLogFileName = val; }

    void WriteTraceLog( const CString& strTraceMsg );

    CString RebuildLogFileName(const CString& strLogFileName);


};

